package com.example.fw;

import org.netbeans.jemmy.operators.JDialogOperator;
import org.netbeans.jemmy.operators.JFrameOperator;
import org.netbeans.jemmy.operators.JLabelOperator;

import javax.swing.*;

public abstract class HelperBase {

	protected AppManager manager;
	public boolean acceptNextAlert = true;
    protected final JFrameOperator mainFrame;
	
	public HelperBase(AppManager manager) {
		this.manager = manager;
        this.mainFrame = manager.getApplication();
	}


    protected String waitMessageDialog(String title, int timeout) {
        long startTime = System.currentTimeMillis();
        long currentTime = startTime;
        while (currentTime < startTime + timeout) {
            JDialog dialog = JDialogOperator.findJDialog(mainFrame.getOwner(), title, false, false);
            if (dialog!= null) {
                JDialogOperator dialogOp = new JDialogOperator(dialog);
                String message = "Warning: " + new JLabelOperator(dialogOp).getText();
                dialogOp.requestClose();
                return message;
            }
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            currentTime = System.currentTimeMillis();
        }
        return null;
    }

}
